<?php echo $this->fetch('header.html'); ?>
<div id="rightTop">
    <p>统计</p>
    <?php echo $this->fetch('subnav.html'); ?>
</div>
<div class="mrightTop">
    <div class="fontl">
        <form method="get">
            <div class="left">
                <input type="hidden" name="app" value="stat_aftersale" />
                <input type="hidden" name="act" value="refund" />
                <div class="left">
                    <select name="search_type" id="search_type" class="querySelect">
                        <option value="day" <?php if ($this->_var['search_arr']['search_type'] == 'day'): ?>selected<?php endif; ?>>按照天统计</option>
                        <option value="week" <?php if ($this->_var['search_arr']['search_type'] == 'week'): ?>selected<?php endif; ?>>按照周统计</option>
                        <option value="month" <?php if ($this->_var['search_arr']['search_type'] == 'month'): ?>selected<?php endif; ?>>按照月统计</option>
                    </select>
                </div>
                <div id="searchtype_day" style="display:none;" class="left">
                    <input class="txt date" type="text" value="<?php echo local_date("Y-m-d",$this->_var['search_arr']['day']['search_time']); ?>" id="search_time" name="search_time">
                </div>
                <div id="searchtype_week" style="display:none;" class="left">
                    <select name="searchweek_year" class="querySelect">
                        <?php $_from = $this->_var['year_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['search_arr']['week']['current_year'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="searchweek_month" class="querySelect">
                        <?php $_from = $this->_var['month_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['search_arr']['week']['current_month'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="searchweek_week" class="querySelect">
                        <?php $_from = $this->_var['week_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['v']['key']; ?>" <?php if ($this->_var['search_arr']['week']['current_week'] == $this->_var['v']['key']): ?>selected<?php endif; ?>><?php echo $this->_var['v']['val']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                </div>
                <div id="searchtype_month" style="display:none;" class="left">
                    <select name="searchmonth_year" class="querySelect">
                        <?php $_from = $this->_var['year_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['search_arr']['month']['current_year'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                    <select name="searchmonth_month" class="querySelect">
                        <?php $_from = $this->_var['month_arr']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('k', 'v');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['v']):
?>
                        <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['search_arr']['month']['current_month'] == $this->_var['k']): ?>selected<?php endif; ?>><?php echo $this->_var['v']; ?></option>
                        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
                    </select>
                </div>
                <input type="submit" class="formbtn" value="查询" />
                <input type="hidden" id="export_type" name="export_type" data-param='{"url":"<?php echo $this->_var['actionurl']; ?>&exporttype=excel"}' value="excel"/>
                <a class="btn1" href="javascript:void(0);" id="export_btn"><span>导出Excel</span></a>
            </div>
        </form>
    </div>
</div>

<div class="stat_info">
         <span>退款总金额：<strong>¥<?php echo (htmlspecialchars($this->_var['count_arr']['total']) == '') ? '0.00' : htmlspecialchars($this->_var['count_arr']['total']); ?></strong>元</span>                
</div>
<div class="tdare">
    <div id="container" class="" style="height:400px"></div>
</div>
<div class="tdare" id="statlist">
</div>
<script>
    $(function() {
        //统计数据类型
        var s_type = $("#search_type").val();
        $('#search_time').datepicker({dateFormat: 'yy-mm-dd'});

        show_searchtime();
        $("#search_type").change(function() {
            show_searchtime();
        });
        //展示搜索时间框
        function show_searchtime() {

            s_type = $("#search_type").val();

            $("[id^='searchtype_']").hide();

            $("#searchtype_" + s_type).show();
        }

        //更新周数组
        $("[name='searchweek_month']").change(function() {
            var year = $("[name='searchweek_year']").val();
            var month = $("[name='searchweek_month']").val();
            $("[name='searchweek_week']").html('');
            $.getJSON('index.php?app=stat_member&act=getweekofmonth', {y: year, m: month}, function(data) {
                if (data != null) {
                    for (var i = 0; i < data.length; i++) {
                        $("[name='searchweek_week']").append('<option value="' + data[i].key + '">' + data[i].val + '</option>');
                    }
                }
            });
        });

        $('#container').highcharts(<?php echo $this->_var['stat_json']; ?>);
        $('#statlist').load('index.php?app=stat_aftersale&act=refundlist&t=<?php echo $this->_var['searchtime']; ?>');
        //导出图表
        $("#export_btn").click(function() {
            var item = $("#export_type");
            var type = $(item).val();
            if (type == 'excel') {
                download_excel(item);
            }
        });

    });

</script>


<?php echo $this->fetch('footer.html'); ?>